﻿import {useEffect} from "react";

function useKey(key,action){
    useEffect(
        function () {
            function callback(e) {
                if (e.code.toLocaleString() === key.toLowerCase()) {
                    action();
                }
            }

            document.addEventListener('keydown', callback);

            return function () {
                document.removeEventListener('keydown', callback);
            }

        }, [action,key]);
}

export default useKey;